package com.reform.controller.common;


import com.reform.res.Result;
import com.reform.res.ResultCode;
import com.reform.service.IDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.net.URLDecoder;
import java.sql.SQLException;

/**
 * <p>
 * 学院表 前端控制器
 * </p>
 *
 * @author mortale
 * @since 2021-06-27
 */
@Api(tags = "DepartmentController")
@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    IDepartmentService departmentService;

    @ApiOperation(value = "获取学校全部部门信息")
    @GetMapping("/getSchoolDepartments")
    public Result getSchoolDepartments() throws SQLException {
        return departmentService.getSchoolDepartments();
    }

    @ApiOperation(value = "获取本地库全部部门信息")
    @GetMapping("/getDepartments")
    public Result getDepartments() throws SQLException {
        return Result.success(ResultCode.SUCCESS, departmentService.getAuthDepartment());
    }

    @ApiOperation(value = "模糊查询部门信息-暂弃用")
    @GetMapping("/getSchoolDepartmentsByArgs")
    @ApiImplicitParam(name = "args", value = "部门模糊信息", paramType = "query", dataTypeClass = String.class, required = true)
    public Result getSchoolDepartmentsByArgs(String args) throws SQLException {
        return departmentService.getSchoolDepartmentsByArgs(args);
    }

    /**
     * 此处需要部门名称原因主要是因为涉及
     *
     * @param dep_id
     * @param dep_name
     * @return
     */
    @ApiOperation(value = "授权部门")
    @PostMapping("/authDepartment")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dep_id", value = "部门编号", paramType = "query", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(name = "dep_name", value = "部门名称", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result authDepartment(Integer dep_id, String dep_name) throws SQLException {
        return departmentService.authDepartment(dep_id, dep_name);
    }



    /**
     * 获取全部学校部门数据 只获取部门编号和名称
     *
     * @return
     */
    @ApiOperation(value = "只获取部门编号和名称")
    @GetMapping("/getSimplifyDepartment")
    public Result getSimplifyDepartment() throws SQLException {
        return departmentService.getSimplifyDepartment();
    }



}
